<template>
  <div class="crimeSceneList">
    <div class="crimeSceneList_left">
      <!-- 业务组织架构 -->
      <div v-show="orgFlag == '2'">
        <div class="organTit">
          <h3>业务组织架构</h3>
          <!-- <Button type="primary" @click="changeOrg(2)">切换为OA架构</Button> -->
        </div>
        <Tree :data="treeListBusiness" @on-select-change="treeChangeBusiness"
          class="tree_render">
        </Tree>
      </div>
      <!-- OA组织架构 -->
      <!-- <div v-show="orgFlag == '1'">
        <div class="organTit">
          <h3>OA组织架构</h3>
          <Button type="primary" @click="changeOrg(1)">切换为业务架构</Button>
        </div>
        <Tree :data="treeList" @on-select-change="treeChange" class="tree_render">
        </Tree>
      </div> -->
    </div>
    <div class="crimeSceneList_right">
      <right-list ref="list" :treeList="treeList"></right-list>
    </div>
  </div>
</template>

<script>
  import rightList from './adjustmentList.vue'
  import crimeOpt from './opt/listOpt'
  import organApi from '@/biz/backStage/organizationManagement'
  import secret from '@/common/secretCode.js'
  export default {
    components: {
      rightList,
    },
    data() {
      return {
        treeList: [],
        orgFlag: '2', //组织架构切换(1: OA 2: 业务) 
        treeListBusiness: [],
        BusinessOrgId: '',
        OAorgId: ''
      }
    },

    computed: {},
    watch: {},
    methods: {
      //切换
      // changeOrg(type) {
      //   console.log(this.treeListBusiness, this.treeList)
      //   if (type == 1) {
      //     this.orgFlag = '2'
      //     this.treeListBusiness.length > 0 && this.$refs.list.getParams(this.BusinessOrgId,
      //       this
      //       .orgFlag)
      //   } else {
      //     this.orgFlag = '1'

      //     this.treeList.length > 0 && this.$refs.list.getParams(this.OAorgId, this.orgFlag)
      //   }
      // },
      //获取部门列表
      // getDepartmentList() {
      //   let parmas = {
      //     appId: this.$dt.userInfo().appId,
      //     userId: this.$dt.userInfo().userId,
      //     roleId: this.$dt.userInfo().role.roleId,
      //     delFlag: 2
      //   }
      //   crimeOpt.getDepartmentList(parmas).then(res => {
      //     console.log(res, 'OA架构')
      //     this.treeList = res
      //     if (res.length > 0) {
      //       this.OAorgId = res[0].orgId
      //     }

      //   })
      // },
      // treeChange(event) {
      //   console.log(event, '点击了树结构')
      //   if (!event.length) {
      //     this.treeList[0].selected = true
      //     this.OAorgId = this.treeList[0].orgId
      //   } else {
      //     this.OAorgId = event[0] ? event[0].orgId : ''
      //   }

      //   this.$refs.list.getParams(this.OAorgId, this.orgFlag)
      // },
      //获取业务组织架构
      getBusinessList() {
        crimeOpt.getBusinessList().then(res => {
          console.log(res, '我是业务组织架构');
          this.treeListBusiness = res
          if (res.length > 0) {
            this.BusinessOrgId = res[0].orgId
            // this.getBtnCode(this.treeListBusiness[0])

            this.$refs.list.getParams(res[0].orgId, res[0].level)
          }
        })
      },
      treeChangeBusiness(event) {
        console.log(event, '点击了树结构')
        let level = ''
        if (!event.length) {
          this.treeListBusiness[0].selected = true
          this.BusinessOrgId = this.treeListBusiness[0].orgId
          level = this.treeListBusiness[0].level
        } else {
          this.BusinessOrgId = event[0] ? event[0].orgId : ''
          level = event[0].level
        }

        this.$refs.list.getParams(this.BusinessOrgId, level)

        // 点击业务组织更改btn的code
        // this.getBtnCode(event[0])


      },

      // getBtnCode(event) {
      //   let parmas1 = {
      //     roleId: this.$dt.userInfo().role.roleId,
      //     userId: this.$dt.userInfo().userId,
      //   }
      //   if (event.authId) {
      //     parmas1.authId = event.authId
      //   } else {
      //     parmas1.orgId = event.orgId
      //   }

      //   organApi.clickMenuCode(parmas1).then(res => {
      //     window.sessionStorage.setItem('buttonControl', secret.Encrypt(JSON.stringify(res
      //       .buttonMenuCodeList)))

      //   })
      // },
    },
    mounted() {
      // this.getDepartmentList()
      this.getBusinessList()
    },
  }
</script>
<style lang='scss' scoped>
  .crimeSceneList {
    padding: 20px;
    height: 100%;
    width: 100%;
    display: flex;

    &_left {
      flex: 0 0 300px;
      padding: 0 10px;
      height: 100%;
      border: 1px solid #ccc;
      margin-right: 20px;
      border-radius: 8px;
      max-height: 100%;
      overflow-y: auto;
      position: relative;

      .organTit {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        padding: 15px 10px;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
      }

      .tree_render {
        margin-top: 62px;
      }
    }

    &_right {
      flex: 1;
      height: 100%;
      border: 1px solid #ccc;
      border-radius: 8px;
      padding: 20px;
      overflow-x: auto;
    }

    ::v-deep .ivu-tree-title {
      width: calc(100% - 15px);
    }
  }
</style>